
package com.dotflat.fin.repository;

import com.dotflat.fin.domain.FinPlanOrder;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface FinPlanOrderRepository extends JpaSpecificationExecutor<FinPlanOrder>, JpaRepository<FinPlanOrder, String> {

    FinPlanOrder findFirstByOrderSn(String orderSN);

    FinPlanOrder findByAreaIdAndId(String areaId, String id);
//    @Query(value = "SELECT * FROM fin_pay_order AS fp WHERE fp.areaId=?1 and fp.id = ?2", nativeQuery = true)
//    FinPlanOrder findByAreaIdAndId(String areaId, String id);
//    FinPlanOrder findById(String id);

    List<FinPlanOrder> findAllByAreaIdAndPlanId(String areaid, String planId);

    List<FinPlanOrder> findAllByClienteleIdInAndCancelledIsFalse(List<String> clienteleIds);
    List<FinPlanOrder> findAllByClienteleIdInAndPayStatusAndCancelledIsFalse(List<String> clienteleIds, Integer payStatus);
    
    Long countAllByPlanIdAndPayStatus(String planId, Integer payStatus);
    Long countAllByPlanId(String planId);

}
